<template>
  <el-dialog
    :title="row.workStatus === 0 ? '启用车辆' : '停用车辆'"
    :visible="dialogVisible"
    width="500px"
    @close="onClose"
  >
    <p>确定要停用吗？车辆停用需满足以下条件：</p>
    <span class="one"><p class="pone">1</p> 车辆当前无运输任务</span>
    <span class="two"><p class="ptwo">2</p> 车辆无关联运输线路</span>
    <p
      v-if="row.workStatus === 1"
      style="color: #ffbe28;"
    >注:停用后司机将自动解除绑定</p>
    <div class="box">
      <el-button
        size="mini"
        @click="onClose"
      >取 消</el-button>
      <el-button
        type="danger"
        size="mini"
        @click="onEdit"
      >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { truckTypeUpdate } from '@/api/transit'
export default {
  name: 'WorkStatusDialog',
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default: null
    }
  },
  methods: {
    onClose() {
      this.$emit('update:dialogVisible', false)
    },
    async onEdit() {
      if (this.row.workStatus === 1) {
        const data = { ...this.row }
        data.workStatus = 0
        await truckTypeUpdate(this.row.id, data)
        this.$emit('update')
        this.$message.success('停用成功')
        this.onClose()
      }
      if (this.row.workStatus === 0) {
        const data = { ...this.row }
        data.workStatus = 1
        await truckTypeUpdate(this.row.id, data)
        this.$emit('update')
        this.$message.success('启用成功')
        this.onClose()
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.one {
    margin-right: 100px;
    .pone {
        display: inline-block;
        height: 15px;
        width: 15px;
        line-height: 15px;
        text-align: center;
        border-radius: 10px;
        background-color: #fafcff;
        border: 1px solid #f0f3f8;
    }
}
.two {
    .ptwo {
        display: inline-block;
        height: 15px;
        width: 15px;
        line-height: 15px;
        text-align: center;
        border-radius: 10px;
        background-color: #fafcff;
        border: 1px solid #f0f3f8;
    }
}
.box {
    margin-left: 280px;
}
</style>
